package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.mapper.OrdersMapper;
import com.qf.java2201.pojo.Orders;
import com.qf.java2201.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("ordersService")
public class OrdersServicelmpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public PageVo<Orders> getPageData(Map<String, Object> params) {
        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<Orders> orders = ordersMapper.selectByParams(params);


        PageInfo<Orders> ordersPageInfo = new PageInfo<>(orders);

        // 把分页数据 封装到 PageVo      这个 PageVo  符合 layui 的  列表数据格式
        PageVo<Orders> ordersPageVo = new PageVo<>();
        ordersPageVo.setData(ordersPageInfo.getList());
        ordersPageVo.setCode(0);
        ordersPageVo.setCount(ordersPageInfo.getTotal());
        ordersPageVo.setMsg("订单管理");
        return ordersPageVo;
    }




    @Override
    public int addOrders(Orders orders) {
        return ordersMapper.addOrders(orders);
    }



    @Override
    public int updateOrders(Orders orders) {

        return ordersMapper.updateOrders(orders);
    }

    @Override
    public int deleteOrders(Integer id) {
        return ordersMapper.deleteOrders(id);
    }
}
